/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
var ListPaging = function(){};
ListPaging.prototype = {
    getData: function(up){
        var t= this;
        t.pa.find('.ajax-loading').removeClass('noVis');
        $.get(this.u_get + '&'+ this.qf.serialize(), up, function(r){t.showData(r)});
    },
    showData: function(r){
        if(!checAjaxRe(r))return;
        this.u_get = r.u_get;
        this.showPaging(r.paging);
        this.showList(r.res);
    },
    showList: function(res){
        this.ta.find('.l-body').html(res);
    },
    showPaging: function(pag){
        var str = '';
        if (pag.p>1)
            str += '<a class="page prev" i_ID="'+ (pag.p -1) +'">&lt;</a>';
        str += '<span class="n">';
        for(var i in pag.page_li){ 
            n = pag.page_li[i];
            if (n==pag.p)
                str += '<span class="edit active" i_ID="'+ n +'">'+ n +'</span>';
            else
                str += '<a class="page" i_ID="'+ n +'">'+ n +'</a>';
        }
        str += '</span>';
        if (pag.p<pag.pages)
            str += '<a class="page next" i_ID="'+ (pag.p +1) +'">&gt;</a>';
        str += '&nbsp;&nbsp;'+ language._('mei ye') +'<span class="edit limit">'+ pag.limit +'</span>'+ language._('tiao');
        str += '，'+ language._('gong') +'<span class="num">'+ pag.num +'</span>' + language._('tiao'); 
        str += '<span class="ajax-loading noVis"></span>';
        this.pa.html(str);
    }
};
ListPaging.init = function(lobj, pobj, gForm){
    var T = new ListPaging();
    T.ta = $(lobj);
    T.pa = $(pobj);
    T.qf = $(gForm);
    
    //paging
    $('.page', T.pa).live('click', function(){ T.getData( 'p='+ $(this).attr('i_ID') );});
    $('.active', T.pa).live('click',function(){ q_edit(this, function(v){T.getData('p='+ v); }); });
    $('.limit', T.pa).live('click', function(){ q_edit(this, function(v){T.qf.find('.s-limit').val(v);T.getData();; }); });
    //ordering
    T.ta.find('.ordering-col').click(function(){
        var a = $(this).toggleClass('ordering-desc');
        T.qf.find('.s-ordering-way').val( a.hasClass('ordering-desc') ? 'DESC':'ASC');
        T.qf.find('.s-ordering-col').val( a.attr('data-col'));
        T.getData();
    });

    return T;
};